package com.tanhua.model.vo;

import com.tanhua.model.mongo.Option;
import com.tanhua.model.mongo.Questions;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class QuestionsVo implements java.io.Serializable {

    /**
     * 主键id
     */
    private String id;
    /**
     * 题目标题
     */
    private String question;
    /**
     * 题目选项
     */
    private List<OptionVo> options;

    public static QuestionsVo init(Questions questions){
        QuestionsVo vo = new QuestionsVo();

        vo.setId(String.valueOf(questions.getId()));
        vo.setQuestion(questions.getQuestion());
        List<OptionVo> optionVos = questions.getOptions().stream().map(option -> OptionVo.init(option)).collect(Collectors.toList());
        vo.setOptions(optionVos);

        return vo;
    }
}